package com.platform.service;

import com.platform.dao.ApiUserLevelMapper;
import com.platform.dao.ApiUserMapper;
import com.platform.dao.ApiWithdrawMapper;
import com.platform.entity.SmsLogVo;
import com.platform.entity.UserLevelVo;
import com.platform.entity.UserVo;
import com.platform.entity.WithdrawVo;
import com.platform.util.CommonUtil;
import com.platform.utils.DateUtils;
import com.platform.utils.RRException;
import com.platform.validator.Assert;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;


@Service
public class ApiWithdrawService {
    @Autowired
    private ApiWithdrawMapper withdrawDao;

    @Transactional
    public WithdrawVo apply(UserVo loginUser, WithdrawVo withdrawVo){
        withdrawVo.setApplyUserId(loginUser.getUserId());
        withdrawVo.setApplyUserName(loginUser.getUsername());
        BigDecimal charge = calcCharge(loginUser, withdrawVo);
        withdrawVo.setWithdrawSn(CommonUtil.generateOrderNumber());
        withdrawVo.setWithdrawCharge(charge);
        withdrawVo.setWithdrawRealityMoney(withdrawVo.getApplyMoney().subtract(charge));
        withdrawVo.setStatus(WithdrawVo.STATUS_SUBMIT);
        withdrawVo.setApplyDate(new Date());
        withdrawDao.apply(withdrawVo);
        return withdrawVo;
    }

    private BigDecimal calcCharge(UserVo loginUser, WithdrawVo withdrawVo){
        return BigDecimal.ZERO;
    }

    public WithdrawVo getApplying(UserVo loginUser){
        return withdrawDao.getApplying(loginUser.getUserId(), WithdrawVo.STATUS_SUBMIT);
    }


    public List<WithdrawVo> queryList(Map<String, Object> map){
        return withdrawDao.queryList(map);
    }

    public int queryTotal(Map<String, Object> map){
        return withdrawDao.queryTotal(map);
    }
}
